import Express from "express"
import {
   UserRouter
} from "./Router/user.js";
import {
   CaptchaRouter
} from "./Router/captcha.js";
import cookieParser from "cookie-parser";
import Session from "express-session";
import "./DB/initDB.js"
import  {errorMiddleware}  from "./Service/middleware/errorMiddleware.js";
import { UploadRouter } from "./Router/upload.js";
import { typeRouter } from "./Router/type.js";
import { articleRouter } from "./Router/article.js";
import { commentRouter } from "./Router/comment.js";

const server = Express();
server.use(Express.json());
server.use(cookieParser());
server.use(Express.static("./static/avatar"))
server.use(Express.static("./static/upload"))
server.use(Session({
   secret: "buka",
   saveUninitialized: true,
   resave: true
}))

server.use("/api/user", UserRouter)
server.use("/api/captcha", CaptchaRouter)
server.use("/api/upload", UploadRouter)
server.use("/api/type", typeRouter)
server.use("/api/issue", articleRouter)
server.use("/api/comment",commentRouter)
server.use(errorMiddleware)

server.listen(8090, () => {
   console.log('服务器运行在8090端口');
})